package com.ydgk.ajax;

import com.alibaba.fastjson.JSON;
import com.ydgk.bean.Teacher;
import com.ydgk.dao.TeacherDao;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

@WebServlet(name = "TeacherUpdateAjaxServlet", urlPatterns = "/TeacherUpdateAjaxServlet.action")
public class TeacherUpdateAjaxServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Teacher teacher = new Teacher();
        try {
            BeanUtils.populate(teacher,request.getParameterMap());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        TeacherDao teacherDao = new TeacherDao();
        int i = teacherDao.updateById(teacher);
        Map map = new HashMap();
        map.put("flag",i>0?true:false);
        response.getWriter().print(JSON.toJSONString(map));
    }


}
